package cn.cloud.project.openfeign.api;

import cn.cloud.project.openfeign.api.configuration.ProviderApiConfiguration;
import cn.cloud.project.openfeign.api.fallbackFactory.ProviderApiFallbackFactory;
import feign.Request;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

// value 或 name 设置服务提供者应用名称可以结合注册中心实现负载均衡
//@FeignClient(value = "demo-provider", contextId = "providerApiClient", fallback = ProviderApiFallback.class)
@FeignClient(value = "demo-provider", contextId = "providerApiClient", fallbackFactory = ProviderApiFallbackFactory.class, configuration = ProviderApiConfiguration.class)
public interface ProviderApiClient {

    /**
     * 如果有参数，一定要加@RequestParam注解
     */
    @GetMapping("/openApi/test")
    String test(@RequestParam("id") String id);

    @GetMapping("/openApi/timeout")
    String timeout();

    /**
     * 单独接口设置超时时间
     */
    @GetMapping("/openApi/timeout")
    String timeout(Request.Options options);

    /**
     * 测试文件上传:
     * 文件参数要用 @RequestPart，不能用@RequestParam
     */
    @PostMapping(value = "/openApi/uploadImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String uploadImage(@RequestPart("file") MultipartFile file);
}
